//
//  ViewController.swift
//  swiftDemo
//
//  Created by Gerry on 2021/10/27.
//

import UIKit
import SnapKit
import CoreMedia

class ViewController: UIViewController {

    var pView : UIView = {
        let v = UIView.init(frame: .zero)
        return v
    }()
    
    var ppView : UIView = UIView()
    var lab : UILabel = UILabel.init(frame: .zero)
    var lab2 : UILabel = UILabel.init(frame: .zero)
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        self.view.backgroundColor = UIColor.white
        let label = UILabel.init(frame: CGRect.init(x: 10, y: 50, width: 100, height: 60))
        label.text = "Hello world"
        self.view.addSubview(label)

        ppView.addSubview(pView)
        view.addSubview(ppView)
        ppView.snp.makeConstraints { make in
            make.left.equalTo(50)
            make.top.equalTo(100)
            make.size.equalTo(CGSize.init(width: 300, height: 300))
        }
        
        pView.backgroundColor = .orange
        
        pView.addSubview(lab)
        lab.text = "测试"
        lab.backgroundColor = .purple
        
        pView.addSubview(lab2)
        lab2.text = "开发"
        lab2.backgroundColor = .yellow
        
        lab.snp.makeConstraints { make in
            make.left.equalTo(10)
            make.top.equalTo(0)
            make.right.equalTo(0)
        }
        lab2.snp.makeConstraints { make in
            make.top.equalTo(lab.snp.bottom).offset(5)
            make.left.equalTo(lab)
            make.right.equalTo(0)
            make.bottom.equalTo(pView)
        }
//        pView.autoresizingMask = .flexibleHeight
        
        pView.translatesAutoresizingMaskIntoConstraints = false
        
        ppView.layoutIfNeeded()
        print("\(pView)")
        
        let btn = UIButton.init(type: .custom)
        btn.setTitle("测试按钮", for: .normal)
        btn.backgroundColor = .red
        view.addSubview(btn)
        btn.addTarget(self, action: #selector(testPressed), for: .touchUpInside)
        
        btn.snp.makeConstraints { make in
            make.left.equalTo(20)
            make.top.equalTo(500)
        }
    }

    @objc
    func testPressed() {
        print("")
    }
}

